package com.hello.system.service.impl;

import java.util.List;
import com.hello.common.core.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hello.system.mapper.RentalOrdersMapper;
import com.hello.system.domain.RentalOrders;
import com.hello.system.domain.dto.RentalOrdersWithDetailsDto;
import com.hello.system.service.IRentalOrdersService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 租赁订单Service业务层处理
 * 
 * @author hello
 * @date 2025-07-20
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RentalOrdersServiceImpl extends ServiceImpl<RentalOrdersMapper, RentalOrders> implements IRentalOrdersService 
{
    private final RentalOrdersMapper rentalOrdersMapper;

    /**
     * 查询租赁订单
     * 
     * @param orderId 租赁订单主键
     * @return 租赁订单
     */
    @Override
    public RentalOrders selectRentalOrdersByOrderId(Long orderId)
    {
        return rentalOrdersMapper.selectRentalOrdersByOrderId(orderId);
    }

    /**
     * 查询租赁订单列表
     * 
     * @param rentalOrders 租赁订单
     * @return 租赁订单
     */
    @Override
    public List<RentalOrders> selectRentalOrdersList(RentalOrders rentalOrders)
    {
        return rentalOrdersMapper.selectRentalOrdersList(rentalOrders);
    }

    /**
     * 新增租赁订单
     * 
     * @param rentalOrders 租赁订单
     * @return 结果
     */
    @Override
    public int insertRentalOrders(RentalOrders rentalOrders)
    {
        rentalOrders.setCreateTime(DateUtils.getNowDate());
        return rentalOrdersMapper.insertRentalOrders(rentalOrders);
    }

    /**
     * 修改租赁订单
     * 
     * @param rentalOrders 租赁订单
     * @return 结果
     */
    @Override
    public int updateRentalOrders(RentalOrders rentalOrders)
    {
        rentalOrders.setUpdateTime(DateUtils.getNowDate());
        return rentalOrdersMapper.updateRentalOrders(rentalOrders);
    }


    /**
     * 批量删除租赁订单
     * 
     * @param orderIds 需要删除的租赁订单主键
     * @return 结果
     */
    @Override
    public int deleteRentalOrdersByOrderIds(Long[] orderIds)
    {
        return rentalOrdersMapper.deleteRentalOrdersByOrderIds(orderIds);
    }

    /**
     * 删除租赁订单信息
     * 
     * @param orderId 租赁订单主键
     * @return 结果
     */
    @Override
    public int deleteRentalOrdersByOrderId(Long orderId)
    {
        return rentalOrdersMapper.deleteRentalOrdersByOrderId(orderId);
    }

    /**
     * 查询当前用户的租赁订单列表（包含设备名称和地址详细信息）
     * 
     * @param rentalOrders 租赁订单查询条件
     * @return 租赁订单详情集合
     */
    @Override
    public List<RentalOrdersWithDetailsDto> selectMyRentalOrdersWithDetails(RentalOrders rentalOrders)
    {
        log.info("======== Service: 查询用户订单详情列表 ========");
        log.info("查询参数: {}", rentalOrders);
        
        List<RentalOrdersWithDetailsDto> result = rentalOrdersMapper.selectMyRentalOrdersWithDetails(rentalOrders);
        log.info("查询结果数量: {}", result != null ? result.size() : 0);
        
        return result;
    }
}
